
import Vue from 'vue'
import VueRouter from 'vue-router'

/**解决router重复报错 */
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)
	   
const Individuation = () => import('views/individuation/Individuation');
const MusicListDetail = () => import('views/list-detail/MusicListDetail');
const AllMusicList = () => import('views/music-list/AllMusicList')
const RankList = () => import('views/rank-list/RankList')
const ArtistCategory = () => import('views/artist-list/ArtistCategory')
const ArtistDetail = () => import('views/list-artist/ArtistDetail')
const Mv = () => import('views/mv/Mv')
const AllMv = () => import('views/mv/childPage/allMv')
const MvDetail = () => import('views/list-mv/MvDetail')
const NewSongs = () => import('views/new-songs/NewSongs')
const Test = () => import('views/test/Test')
// 搜索详情
const SearchDetail = () => import('views/search-detail/SearchDetail')
const SearchSongs = () => import('views/search-detail/childsPage/search-songs')
const SearchArtist = () => import('views/search-detail/childsPage/search-artist')
const SearchPlaylist = () => import('views/search-detail/childsPage/search-playlist')
const SearchAlbum = () => import('views/search-detail/childsPage/search-album')
const SearchMv = () => import('views/search-detail/childsPage/search-mv')
const routes = [
    {
        path: '/',
        redirect: '/individuation'
    },
    {
        path: '/individuation',
        component: Individuation
    },
	{
	    path: '/musicListdetail/:id/:time',
	    component: MusicListDetail,
	    name: 'MusicListDetail',
	},
   {
         path: '/allmusic-list',
         component: AllMusicList
     },
   	{
   	      path: '/rank-list',
   	      component: RankList
   	},
   	{
   	    path: '/artist-list',
   	    component: ArtistCategory
   	},
	{
	    path: '/artistdetail/:id',
	    component: ArtistDetail,
		name:'ArtistDetail'
	},
    {
   	    path: '/mv',
   	    component: Mv
   	},
	{
	    path: '/mv/:id',
	    component: MvDetail,
		name:'MvDetail'
	},
	{
		path: '/allMv',
		component: AllMv,
		name:'AllMv'
	},
   	{
   		path: '/new-songs',
   		component: NewSongs
   	},
	{
		path: '/test',
		component: Test
	},
	{
	    path: '/search-detail/:keywords',
	    name: 'search-detail',
	    component: SearchDetail,
		children: [
		    {
		        path: '/',
		        redirect: 'songs'
		    },
		    {
		        path: 'songs',
		        name: 'search-songs',
		        component: SearchSongs,
		    },
		    {
		        path: 'artist',
		        name: 'search-artist',
		        component: SearchArtist,
		    },
		    {
		        path: 'album',
		        name: 'search-album',
		        component: SearchAlbum,
		    },
		    {
		        path: 'playlist',
		        name: 'search-playlist',
		        component: SearchPlaylist,
		    },
		    {
		        path: 'mv',
		        name: 'search-mv',
		        component: SearchMv,
		    }
		]
	},
 
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
//守卫导航钩子
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     next();
//   } else {
//     let token = localStorage.getItem('Authorization');
 
//     if (token === null || token === '') {
//       next('/login');
//     } else {
//       next();
//     }
//   }
// });
// router.onError((error) => {
//   const pattern = /Loading chunk (\d)+ failed/g;
//   const isChunkLoadFailed = error.message.match(pattern);
//   const targetPath = router.history.pending.fullPath;
//   if (isChunkLoadFailed) {
//     router.replace(targetPath);
//   }
// });


export default router
